<?php
/**
 * Spaph_Plugin
 *
 * A spaph plugin class extends Spaph_Plugin. Override one or all of
 * the following methods: _preDispatch, _postDispatch, _filter. Even
 * __construct can be overriden - plugins are constructed before any
 * controllers are loaded or known about.
 */
abstract class Spaph_Plugin
{
    public static $ROOT_DIR = '';

    /**
     * Set the root directory of all plugins.
     *
     * @param string $dir
     */
    public static function setPluginDir($dir)
    {
        $parts  = preg_split( '/[\\\\\/]+/', trim(rtrim($dir,'\\/')) );
        self::$ROOT_DIR = implode(DIRECTORY_SEPARATOR,$parts) . DIRECTORY_SEPARATOR;
    }

    /**
     * __construct
     *
     * Plugins are instantiated *before* any controllers have
     * been thought about. A plugin constructor is a good place
     * to call Spaph::getInstance()->setAction(...) or
     * Spaph::getInstance()->setActionParam(...).
     *
     * Plugins are contructed in the the order they are registered via
     * Spaph::getInstance()->regPlugin(...)
     *
     * @return null
     */
    public function __construct()    {}

    /**
     * _preDispatch
     *
     * This is called *after* the controller has run _init but *before*
     * the action is called. The action can be changed during _preDispatch
     * by calling Spaph::getInstance()->setAction().
     *
     * @return null
     */
    public function _preDispatch()   {}

    /**
     * _postDispatch
     *
     * This is called immediately after the action has been run. The plugin
     * whose _preDispatch was called last, will be the first one to _postDispatch.
     *
     * @return null
     */
    public function _postDispatch()  {}

    /**
     * _filter
     *
     * The _filter is called during Spaph_View::render() right after the template
     * file is required/eval()'d. This method is used by a plugin filter to manipulate
     * output from a template.
     *
     * @param string $content
     * @return string
     */
     public function _filter($content)
     {
         return $content;
     }
}


